package com.edu.exam.enums.system;

import com.edu.exam.enums.core.BaseEnum;

/**
 * 附件状态枚举
 *
 * @author System
 * @version 1.0.0
 */
public enum AttachmentStatus implements BaseEnum {

    UPLOADING("UPLOADING", "上传中"),
    ACTIVE("ACTIVE", "可用"),
    PROCESSING("PROCESSING", "处理中"),
    ERROR("ERROR", "错误"),
    DISABLED("DISABLED", "禁用"),
    EXPIRED("EXPIRED", "已过期");

    private final String code;
    private final String description;

    AttachmentStatus(String code, String description) {
        this.code = code;
        this.description = description;
    }

    @Override
    public String getCode() {
        return code;
    }

    @Override
    public String getDescription() {
        return description;
    }

    /**
     * 根据编码查找枚举值
     *
     * @param code 业务编码
     * @return 对应的枚举值
     * @throws IllegalArgumentException 如果编码无效
     */
    public static AttachmentStatus fromCode(String code) {
        for (AttachmentStatus status : values()) {
            if (status.getCode().equals(code)) {
                return status;
            }
        }
        throw new IllegalArgumentException("Unknown AttachmentStatus code: " + code);
    }

    /**
     * 根据描述查找枚举值
     *
     * @param description 显示描述
     * @return 对应的枚举值，null如果未找到
     */
    public static AttachmentStatus fromDescription(String description) {
        if (description == null || description.trim().isEmpty()) {
            return null;
        }

        for (AttachmentStatus value : values()) {
            if (value.getDescription().equals(description)) {
                return value;
            }
        }
        throw new IllegalArgumentException("Unknown AttachmentStatus description: " + description);
    }

    @Override
    public String toString() {
        return description;
    }
}